<template>
   <el-form :inline="true" class="demo-form-inline">
    <el-form-item label="一级分类">
      <el-select placeholder="请选择"  v-model="category1Id" @change="handlerCategory1">
        <el-option :label="c1.name" :value="c1.id" v-for="(c1,index) in category1List" :key="c1.id"/>
      </el-select>
    </el-form-item>

    <el-form-item label="二级分类">
      <el-select placeholder="请选择"  v-model="category2Id" @change="handlerCategory2">
        <el-option :label="c2.name" :value="c2.id" v-for="(c2,index) in category2List" :key="c2.id"/>
      </el-select>
    </el-form-item>

    <el-form-item label="三级分类">
      <el-select placeholder="请选择"  v-model="category3Id">
        <el-option :label="c3.name" :value="c3.id" v-for="(c3,index) in category3List" :key="c3.id"/>
      </el-select>
    </el-form-item>
  </el-form>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  export default defineComponent({
    name:'CategorySelector'
  })
</script>
<script lang="ts" setup>
import { onMounted } from 'vue';
import { useCategoryStore } from '@/stores/category';
import { storeToRefs } from 'pinia';
const  categoryStore=useCategoryStore()
onMounted(()=>{
  categoryStore.getCategory1List()
})
const{category1List,category1Id,category2List,category2Id,category3List,category3Id}=storeToRefs(categoryStore)
const handlerCategory1=()=>{
  categoryStore.getCategory2List()
}
const handlerCategory2=()=>{
  categoryStore.getCategory3List()
}
</script>

<style lang="less" scoped>
</style>
